package com.hqyj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hqyj.pojo.MyPage;
import com.hqyj.pojo.TbChargeDetail;
import com.hqyj.pojo.TbChargeItem;
import com.hqyj.dao.TbChargeItemMapper;
import com.hqyj.service.TbChargeItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.error.MarkedYAMLException;

import java.util.HashMap;

/**
 * <p>
 * 收费项目表 服务实现类
 * </p>
 *
 * @author gp
 * @since 2021-09-25
 */
@Service
public class TbChargeItemServiceImpl implements TbChargeItemService {
    @Autowired
    TbChargeItemMapper tbChargeItemMapper;
    @Override
    public HashMap<String, Object> list(TbChargeItem tbChargeItem) {
        HashMap<String ,Object> map = new HashMap<>();
        Page<TbChargeItem> TbChargeDetailPage = new Page<>(tbChargeItem.getPage(),tbChargeItem.getRow());
        //创建查询条件对象
        QueryWrapper<TbChargeItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(
                tbChargeItem.getCommunityName()!=null&&!tbChargeItem.getRow().equals(""),
                "community_name",
                tbChargeItem.getCommunityName());
        //查询分页，获取分页数据集
        Page<TbChargeItem> pageList = tbChargeItemMapper.selectPage(TbChargeDetailPage,null);
        //获取当前页的集合
        map.put("info",pageList.getRecords());
        //获取总条数
        map.put("total",pageList.getTotal());
        //获得总页数
        map.put("totalPage",pageList.getPages());
        return map;
    }

    @Override
    public HashMap<String, Object> update(TbChargeItem tbChargeItem) {
        HashMap<String,Object> map = new HashMap<>();
        int num = tbChargeItemMapper.updateById(tbChargeItem);
        if (num>0){
            map.put("info","修改成功");
        }else {
            map.put("info","修改失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> insert(TbChargeItem tbChargeItem) {
        HashMap<String,Object> map = new HashMap<>();
        int num = tbChargeItemMapper.insert(tbChargeItem);
        if (num>0){
            map.put("info","添加成功");
        }else {
            map.put("info","添加失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> delete(Integer id) {
        HashMap<String,Object> map = new HashMap<>();
        int num = tbChargeItemMapper.deleteById(id);
        if (num>0){
            map.put("info","删除成功");
        }else {
            map.put("info","删除失败");
        }
        return map;
    }
}
